$(function(){
	//初始化表格
	$('#BanCiTab').datagrid({
	    url:'BanCixx',
	    /* queryParams:{
	    	deptno:10
	    }, */
	    columns:[[
			{field:'SHFID',width:1,checkbox:true,title:'班次编号',align:'center'},
			{field:'SHFNAME',width:1,title:'班次名称',align:'center'},
			{field:'SHFTIME',width:1,title:'班次时间',align:'center'},
			{field:'SHFREM',width:1,title:'班次时间',align:'center'}/*,
			{field:'caozuo',fixed:false,width:1,formatter:operate_formatter,title:'操作',align:'center'}
		*/]],
	    toolbar:'#BanCitb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15] 
	});
	
	function operate_formatter(value, row, index) {
		return "<button class='easyui-linkbutton' onclick='deleteYY("+row.SHFID+")'>删除</button> ";
	}
	
	//点击提交
	$("#updateBC").click(function(){
		var SHFID = $("#SHFID").val();	
		var SHFNAME = $("#SHFNAME").val();
		var SHFTIME = $("#SHFTIME").val()+"-"+$("#SHFTIMEs").val();
		var SHFREM = $("#SHFREM").val();
		if(SHFNAME==null || SHFNAME=="null" || SHFNAME==""){
			return alert("班次名不能为空！");
		}
		if($("#SHFTIME").val()==null || $("#SHFTIME").val()=="null" || $("#SHFTIME").val()=="" || $("#SHFTIMEs").val()==null || $("#SHFTIMEs").val()=="null" || $("#SHFTIMEs").val()==""){
			return alert("请选择时间！");
		}
		
		$.ajax({
			url:"updateBC",
			type:"post",
			data:{"shfid":SHFID,"shfname":SHFNAME,"shftime":SHFTIME,"shfrem":SHFREM},
			success:function(data){
				if(data=="-1"){
					alert("班次不能重名");
				}else{
					$('#BanCiTab').datagrid('reload');
					//清空表单  
					deleteBanCi();
					$("#BanCiwin").window("close");
				}
				
			}
		});
		
	});

	//显示
	$("#BanCiadd").click(function(){
		$("#BanCiwin").window("open");
		deleteBanCi();
		CNDatejging();
	});
});

//拼接字符串
function CNDatejging(){
	var SHFTIME = CNDateString($("#SHFTIME").val());
	var SHFTIMEs = CNDateString($("#SHFTIMEs").val());
	var sss = "";
	CNDateCount($("#SHFTIME").val(), $("#SHFTIMEs").val())==0?sss="到":sss="到次日";
	$("#SHFREM").val(SHFTIME+sss+SHFTIMEs); 
}

//08:00 时间时间 转 汉字时间  八点整
function CNDateString(date) { 
	var split = date.split(":");
	if(split[0]==null || split[0]=="null" || split[1]==null || split[1]=="null"){
		return "";
	}
	var d3 = ["","一","二","三","四","五","六","七","八","九","十"];
	var s1 = parseInt(split[0])>10?d3[parseInt(split[0].split("")[0])]+"十"+d3[parseInt(split[0].split("")[1])]:d3[parseInt(split[0])];
	var s2 = parseInt(split[1])>10?d3[parseInt(split[1].split("")[0])]+"十"+d3[parseInt(split[1].split("")[1])]+"分":d3[parseInt(split[1])]+"分";
	parseInt(split[0])==0?s1="零":s1=s1;
	parseInt(split[1])==0?s2="整":s2=s2;
	return s1+"点"+s2; 
}

//判断时间先后
function CNDateCount(date1, date2){
	var split1 = date1.split(":");
	var split2 = date2.split(":");
	return parseInt(split1[0])>=parseInt(split2[0])?1:0;
}

//清空表单
function deleteBanCi(){
	$("#SHFID").val("");
	$("#SHFNAME").val("");
	$("#SHFTIME").val("08:00");  
	$("#SHFTIMEs").val("18:00"); 
	$("#SHFREM").val("");  
}

//不允许修改
////双击行事件
//$("#BanCiTab").datagrid({
//	//rowData是当前选中行的数据，是json字符串格式
//	onDblClickRow:function(rowIndex,rowData){
//		$("#SHFID").val(rowData["SHFID"]);
//		$("#SHFNAME").val(rowData["SHFNAME"]);
//		var time = rowData["SHFTIME"].split("-");
////		for (var i = 0; i < time.length; i++) {
////			var times = time[i].split(":");
////			if(parseInt(times[0])<10){
////				time[i]="0"+times[0]+":"+times[1];
////			}
////			if(parseInt(times[0])==24){
////				time[i]="00:"+times[1];
////			}
////		}
//		$("#SHFTIME").val(time[0]);
//		$("#SHFTIMEs").val(time[1]);
//		$("#SHFREM").val(rowData["SHFREM"]);
//		$("#BanCiwin").window("open");
//	}
//});

//$(document).ready(function(){
//	$("#SHFTIME").mouseout( function() {
//		alert("?");
//		lgsjpj();
//	});
//	$("#SHFTIMEs").mouseout( function() {
//		lgsjpj();
//	});
//});

//删除方法
function deleteYY(SHFID){
	deleteBG("deleteBC","BanCiTab",{"shfid":SHFID});
}